fix: Workflow publishing name time error#3988
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| name=timezone.localtime(timezone.now()).strftime('%Y-%m-%d %H:%M:%S'), | ||
| publish_user_id=user_id, | ||
| publish_user_name=user.username, | ||
| workspace_id=workspace_id) |
There was a problem hiding this comment.
The publish method currently saves the current time in UTC using timezone.now(). This means that if you're working in a system where daylight saving time (DST) is applicable, your save time will be different from local time.
To avoid this discrepancy, use timezone.localtime(timezone.now()) to ensure the save time matches the user's location. Here’s how you can update your code:
def publish(self, instance, with_valid=True):
application.is_publish = True
application.save()
# Use timezone localtime instead of utcnow for correct saved date and time
work_flow_version = ApplicationVersion(
work_flow=application.work_flow,
application=application,
name=datetime.strftime(application.created_at.astimezone(datetime.now().astimezone(tzinfo=None)), '%Y-%m-%d %H:%M:%S'),
publish_user_id=user_id,
publish_user_name=user.username,
workspace_id=workspace_id
)This change uses the created_at field on ApplicationInstance to get the timestamp which aligns better with what you might want to use when publishing something related to an instance creation date or event datetime, rather than always referring to now which could skew based on DST boundaries.
fix: Workflow publishing name time error